package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.ActivityDO;
import com.example.lotterysystem.dao.dataobject.ActivityPrizeDO;
import com.example.lotterysystem.dao.dataobject.ActivityUserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {
    @Insert("insert into activity(activity_name,description,status) " +
            " values(#{activityName},#{description},#{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id",keyColumn = "id")
    Long insert(ActivityDO activityDO);


    @Select("select count(1) from activity")
    int count();

    @Select("select * from activity order by id desc limit #{offset},#{pageSize}")
    List<ActivityDO> selectByPage(@Param("offset") Integer offset,
                                  @Param("pageSize") Integer pageSize);

    @Select("select * from activity where id = #{id}")
    ActivityDO selectById(@Param("id") Long id);

    @Select("select * from activity_prize where activity_id = #{activityId}")
    List<ActivityPrizeDO> selectActivityPrizeList(@Param("activityId") Long activityId);
@Select("select * from activity_user where activity_id = #{activityId}")
    List<ActivityUserDO> selectActivityUserList(@Param("activityId") Long activityId);

@Select("select * from activity_prize where activity_id = #{activityId} and prize_id = #{prizeId}")
    ActivityPrizeDO selectPrizeById(@Param("prizeId") Long prizeId,@Param("activityId") Long activityId);
@Update("update activity set status = #{status} where id = #{id}")
    void updateStatus(@Param("id") Long activityId,@Param("status") String status);
}
